import Vue from 'vue'
import Vuex from 'vuex'

import VuexPersistence from 'vuex-persist'

const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
  key: "m05b_vueq"
})
import router from "../router/index"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    m_user: {},
    m_token: "",
    addList: [],
  },
  mutations: {
    hjwadd(state, username) {
      state.addList.unshift(username);
    },
    hjwdel(state, index) {
      state.addList.splice(index, 1);
    },
    hjwqx(state,qx) {
      state.addList.forEach(item=>{
        console.log(item.hjwcheck);
        item.hjwcheck=qx;
      })
    },
    hjwfx(state,qx){
      state.addList.forEach(item=>{
        if(item.hjwcheck==true){
            qx=true;
        }
      })
    },
    hjwremove(state){
      state.addList.forEach(item=>{
          state.addList=[];
      })
    }
  },
  actions: {
  },
  modules: {
  },
  getters: {
    num(state) {
      var nums = 0;
      state.addList.forEach(item => {
        if (item.hjwcheck == true) {
          nums++;
        }
      })
      return nums;
    }
  },
  plugins: [vuexLocal.plugin]
})
